package com.zy.activity;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManager;

import com.zy.zlog.ZLog;

public abstract class BaseMainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_main);
        Fragment fragment = getContainerFragment();
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().add(R.id.base_main_container, fragment).commitNowAllowingStateLoss();
        }
    }

    protected abstract Fragment getContainerFragment();

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        ZLog.d("BaseMainActivity", "dispatchKeyEvent:" + event);
        return super.dispatchKeyEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        //ZLog.d("BaseMainActivity", "dispatchTouchEvent:" + ev);
        //ZLog.d("BaseMainActivity", "dispatchTouchEvent "+ev.getAction()+" 相对坐标:[" + ev.getX() + "," + ev.getY() + "] 绝对坐标:[" + ev.getRawX() + "," + ev.getRawY() + "]");
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        boolean result = super.onTouchEvent(event);
        ZLog.d("BaseMainActivity", "onTouchEvent result:" + result);
        return super.onTouchEvent(event);
    }
}